home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / e_v3.2a_extras / pdsrc / showiff.e < prev    next >
Text File  |  1992-09-02  |  2KB  |  72 lines

  1. MODULE 'iff','libraries/iff','intuition/intuition','intuition/screens',
  2.        'exec/memory'
  3.  
  4. ENUM ER_NONE,ER_IFFLIB,ER_OPENIFF,ER_NOBMHD,ER_SCREEN,ER_WINDOW,ER_DECODE
  5.  
  6. DEF iff=NIL,s=NIL,ct[256]:ARRAY OF INT,bmhd,w=NIL:PTR TO window,
  7.     quit=FALSE,msg:PTR TO intuimessage,sprite=NIL
  8.  
  9. PROC main() HANDLE
  10.   /* Open library first */
  11.   IF (iffbase:=OpenLibrary('iff.library',22))=NIL THEN Raise(ER_IFFLIB)
  12.  
  13.   /* arg = filename of IFF file */
  14.   IF (iff:=IfFL_OpenIFF(arg,IFFL_MODE_READ))=NIL THEN Raise(ER_OPENIFF)
  15.  
  16.   /* BMHD = BitMap HeaDer (contains dimensions of picture) */
  17.   IF (bmhd:=IfFL_GetBMHD(iff))=NIL THEN Raise(ER_NOBMHD)
  18.  
  19.   /* Open screen with correct dimensions */
  20.   IF (s:=OpenScreenTagList(NIL,
  21.     [SA_WIDTH,Int(bmhd),SA_HEIGHT,Int(bmhd+2),SA_DEPTH,Char(bmhd+8),
  22.      SA_DISPLAYID,IfFL_GetViewModes(iff),
  23.      0,0]))=NIL THEN Raise(ER_SCREEN)
  24.  
  25.   /* Open a full size dummy window */
  26.   IF (w:=OpenWindowTagList(NIL,
  27.     [WA_LEFT,0,WA_TOP,0,WA_WIDTH,Int(bmhd),WA_HEIGHT,Int(bmhd+2),
  28.      WA_FLAGS,WFLG_SIMPLE_REFRESH OR WFLG_NOCAREREFRESH OR
  29.               WFLG_BORDERLESS OR WFLG_ACTIVATE,
  30.      WA_IDCMP,IDCMP_MOUSEBUTTONS OR IDCMP_RAWKEY,
  31.      WA_CUSTOMSCREEN,s,
  32.      NIL,NIL]))=NIL THEN Raise(ER_WINDOW)
  33.  
  34.   /* Blank the mouse pointer */
  35.   IF sprite:=AllocMem(20,MEMF_CHIP OR MEMF_CLEAR)
  36.     SetPointer(w,sprite,1,16,0,0)
  37.   ENDIF
  38.  
  39.   /* Set the palette of the screen */
  40.   LoadRGB4(s+44,ct,IfFL_GetColorTab(iff,ct))
  41.  
  42.   /* Try to load the picture */
  43.   IF (IfFL_DecodePic(iff,s+184))=FALSE THEN Raise(ER_DECODE)
  44.  
  45.   /* Wait for the user to press a mouse button */
  46.   REPEAT
  47.     IF msg:=GetMsg(w.userport)
  48.       quit:=(msg.class AND (IDCMP_MOUSEBUTTONS OR IDCMP_RAWKEY))
  49.     ELSE
  50.       quit:=(Wait(-1) AND Shl(1,12))
  51.     ENDIF
  52.   UNTIL quit
  53.  
  54.   Raise(ER_NONE)
  55. EXCEPT
  56.   /* Clean up */
  57.   IF w THEN CloseWindow(w)
  58.   IF sprite THEN FreeMem(sprite,20)
  59.   IF s THEN CloseScreen(s)
  60.   IF iff THEN IfFL_CloseIFF(iff)
  61.   IF iffbase THEN CloseLibrary(iffbase)
  62.  
  63.   /* Display possible error message */
  64.   IF exception>0
  65.     WriteF('Error: \s.\n',
  66.       ListItem(['No IFF library','Could not open IFF file',
  67.                 'IFF File had no bitmap header','Could not open screen',
  68.                 'Could not open window','Could not decode picture'],
  69.                 exception-1))
  70.   ENDIF
  71. ENDPROC
  72.